<?php
function getNumArr_6H ($bettype)
{
    $reArr = array();
    switch ($bettype)
    {
        case 1 :
        case 2 :
        case 3 :
        case 47 :
        case 20 :
        case 28 :
        case 30 :
        case 5 :
        case 6 :
        case 35 :
            $reArr = array(1, 2);
            break;
        case 1001 :
        case 1002 :
        case 1003 :
            $i = 1;
            while ($i < 50)
            {
                $reArr[] = $i;
                ++$i;
            }
            break;
        case 13 :
        case 46 :
            $i = 1;
            while ($i < 4)
            {
                $reArr[] = $i;
                ++$i;
            }
            break;
        case 14 :
        case 18 :
        case 1006 :
            $i = 1;
            while ($i < 13)
            {
                $reArr[] = $i;
                ++$i;
            }
            break;
        case 1007 :
            $i = 1;
            while ($i < 11)
            {
                $reArr[] = $i;
                ++$i;
            }
            break;
        case 19 :
            $i = 1;
            while ($i < 12)
            {
                $idx = d2($i);
                $reArr[] = "1_{$idx}";
                $reArr[] = "2_{$idx}";
                ++$i;
            }
            break;
        case 15 :
        case 16 :
        case 17 :
        case 23 :
            $reArrTemp = array(15 => array(), 16 => array(), 17 => array(), 23 => array());
            $i = 1;
            while ($i < 7)
            {
                $reArrTemp['15'][] = "{$i} 1";
                $reArrTemp['15'][] = "{$i} 2";
                $reArrTemp['16'][] = "{$i} 3";
                $reArrTemp['16'][] = "{$i} 4";
                $reArrTemp['17'][] = "{$i} 5";
                $reArrTemp['17'][] = "{$i} 6";
                $reArrTemp['17'][] = "{$i} 7";
                $reArrTemp['23'][] = "{$i} 8";
                $reArrTemp['23'][] = "{$i} 9";
                ++$i;
            }
            $reArr = $reArrTemp[$bettype];
            break;
        case 34 :
            $i = 4;
            while ($i < 8)
            {
                $reArr[] = $i;
                ++$i;
            }
        default :
            $reArr = array();
            break;
    }
    return $reArr;
}

function my_array_fill_keys ($keys, $value)
{
    return array_combine($keys, array_fill(0, count($keys), $value));
}

function getRateArr ($cid, $bettype, $lotto_id = 0, $disk = "a", $subRateFlag = 0)
{
    static $rateArr = array();
    switch ($bettype)
    {
        case 0 :
        case 1001 :
        case 1002 :
        case 1003 :
            $norder = $bettype == 1003 ? min(max(intval(getvar("norder")), 1), 6) : "";
            $tblName = $bettype == 1001 ? "rate0{$disk}" : "rate4{$norder}{$disk}";
            if (!isset($rateArr[$tblName]))
            {
                $rs = getdb_cen($cid, "select * from {$tblName} where lotto_id={$lotto_id}");
                if ($rs->eof)
                {
                    exit("Error ID!");
                }
                $rateArr[$tblName] = $rs->f;
                $rs->close();
            }
            $reArr = array();
            $i = 1;
            while ($i < 50)
            {
                $reArr[$i] = $rateArr[$tblName]["r" . d2($i)] - 0;
                ++$i;
            }
            return $reArr;
        case 1 :
            break;
        case 2 :
            break;
        case 3 :
            break;
        case 47 :
            break;
        case 20 :
            break;
        case 28 :
            break;
        case 30 :
            break;
        case 5 :
            break;
        case 6 :
            break;
        case 35 :
    }
    $tblName = in_array($bettype, array(5, 6)) ? "rate5{$disk}" : "rate1{$disk}";
    if (!isset($rateArr[$tblName]))
    {
        $rs = getdb_cen($cid, "select * from {$tblName} where lotto_id={$lotto_id}");
        if ($rs->eof)
        {
            exit("Error ID!");
        }
        $rateArr[$tblName] = $rs->f;
        $rs->close();
    }
    $reArr = array();
    $reArr[1] = $rateArr[$tblName]["r{$bettype}_1"] - 0;
    $reArr[2] = $rateArr[$tblName]["r{$bettype}_2"] - 0;
    return $reArr;
    switch ($bettype)
    {
        case 13 :
            break;
        case 46 :
    }
    $tblName = "rate1{$disk}";
    if (!isset($rateArr[$tblName]))
    {
        $rs = getdb_cen($cid, "select * from rate1{$disk} where lotto_id={$lotto_id}");
        if ($rs->eof)
        {
            exit("Error ID!");
        }
        $rateArr[$tblName] = $rs->f;
        $rs->close();
    }
    $reArr = array();
    $reArr[1] = $rateArr[$tblName]["r{$bettype}_1"] - 0;
    $reArr[2] = $rateArr[$tblName]["r{$bettype}_2"] - 0;
    $reArr[3] = $rateArr[$tblName]["r{$bettype}_3"] - 0;
    return $reArr;
    switch ($bettype)
    {
        case 14 :
            break;
        case 18 :
            break;
        case 1006 :
            break;
        case 1007 :
            break;
        case 34 :
    }
    $tblName = "rate1{$disk}";
    $betChgArr = array(1006 => 21, 1007 => 22);
    $minI = 1;
    if ($bettype == 1007)
    {
        $maxI = 11;
    }
    else if ($bettype == 34)
    {
        $maxI = 8;
        $minI = 4;
    }
    else
    {
        $maxI = 13;
    }
    $betIdx = isset($betChgArr[$bettype]) ? $betChgArr[$bettype] : $bettype;
    if (!isset($rateArr[$tblName]))
    {
        $rs = getdb_cen($cid, "select * from {$tblName} where lotto_id={$lotto_id}");
        if ($rs->eof)
        {
            exit("Error ID!");
        }
        $rateArr[$tblName] = $rs->f;
        $rs->close();
    }
    $reArr = array();
    $i = $minI;
    while ($i < $maxI)
    {
        $reArr[$i] = $rateArr[$tblName]["r{$betIdx}_{$i}"] - 0;
        ++$i;
    }
    return $reArr;
    switch ($bettype)
    {
        case 19 :
            $tblName = "rate1{$disk}";
            if (!isset($rateArr[$tblName]))
            {
                $rs = getdb_cen($cid, "select * from {$tblName} where lotto_id={$lotto_id}");
                if ($rs->eof)
                {
                    exit("Error ID!");
                }
                $rateArr[$tblName] = $rs->f;
                $rs->close();
            }
            $reArr = array();
            $i = 1;
            while ($i < 12)
            {
                $idx = d2($i);
                $reArr["1_{$idx}"] = $rateArr[$tblName]["r19_1_{$idx}"] - 0;
                $reArr["2_{$idx}"] = $rateArr[$tblName]["r19_2_{$idx}"] - 0;
                ++$i;
            }
            $rs->close();
            return $reArr;
        case 15 :
        case 16 :
        case 17 :
        case 23 :
            $tblName = "rate15{$disk}";
            if (!isset($rateArr[$tblName]))
            {
                $rs = getdb_cen($cid, "select * from {$tblName} where lotto_id={$lotto_id}");
                if ($rs->eof)
                {
                    exit("Error ID!");
                }
                $rateArr[$tblName] = $rs->f;
                $rs->close();
            }
            $reArr = array();
            $i = 1;
            while ($i < 7)
            {
                $reArr["{$i} 1"] = $rateArr[$tblName]["r15_{$i}_1"] - 0;
                $reArr["{$i} 2"] = $rateArr[$tblName]["r15_{$i}_2"] - 0;
                $reArr["{$i} 3"] = $rateArr[$tblName]["r15_{$i}_3"] - 0;
                $reArr["{$i} 4"] = $rateArr[$tblName]["r15_{$i}_4"] - 0;
                $reArr["{$i} 5"] = $rateArr[$tblName]["r15_{$i}_5"] - 0;
                $reArr["{$i} 6"] = $rateArr[$tblName]["r15_{$i}_6"] - 0;
                $reArr["{$i} 7"] = $rateArr[$tblName]["r15_{$i}_7"] - 0;
                $reArr["{$i} 8"] = $rateArr[$tblName]["r15_{$i}_8"] - 0;
                $reArr["{$i} 9"] = $rateArr[$tblName]["r15_{$i}_9"] - 0;
                ++$i;
            }
            return $reArr;
        default :
            $reArr = array();
            break;
    }
    return array();
}

if (!defined("IN_OP_CEN"))
{
    exit("You can't access this file directly....");
}
include_once( "centralize/centralize_class/config_cen.php" );
include_once( "centralize/centralize_class/db_cen.php" );
$cid = intval(getvar("cid"));
if (!isset($g_cen_info[$cid]))
{
    exit("-2, error cid ");
}
$split = intval(getvar("split"));
$playtype = getvar("playtype");
$slc = intval(getvar("slc"));
$lotto_id = intval(getvar("id"));
$subid = intval(getvar("subid"));
$order = intval(getvar("norder"));
$diskStr = "";
$ratemod = 0;
if ($lotto_id < 1)
{
    header("Cache-Control: no-cache, must-revalidate");
    header("Content-Type: text/plain");
    echo "{\"errormsg\":\"no data\"}";
    exit();
}
include( "class_6h/BetTotal_6h.php" );
include( "class_6h/class.menu.php" );
$BetTotal_6h = new BetTotal_6h($lotto_id);
$onlineMenu = new menu_6h(3);
if (!isset($onlineMenu->menuArr[$slc]))
{
    exit("error - 10");
}
$bettypeStr = is_array($onlineMenu->menuArr[$slc][6]) ? $onlineMenu->menuArr[$slc][6][3] : $onlineMenu->menuArr[$slc][6];
$playArr = explode(",", $bettypeStr);
$time = systime() - 30;
$orderBetArr = array(1001 => "特码A+B", 0 => "特码A", 24 => "特码B", 4 => "正码A", 31 => "正码B", 25 => "正码特A", 26 => "正码特B");
if ($curruser['acl'] == 255 || $curruser['acl'] == 300)
{
    $showid = "0";
}
else
{
    $showid = $curruser['id'];
}
$modDiffArr = array();
$showStr = "";
foreach ($playArr as $val)
{
    $val = intval($val);
    $val_subid = $val;
    $tempDataTotal = $BetTotal_6h->getDataListTotal2($lotto_id, $val, $showid, $split, "");
    if ($tempDataTotal != false)
    {
        $dataTotal = intval($tempDataTotal['totalnum']);
        $dataAmount = round($tempDataTotal['amount']);
        $databack2 = intval($tempDataTotal['back2']);
        if (isset($modDiffArr[$val]))
        {
            $databack1 = round($tempDataTotal['back1'] / $modDiffArr[$val]);
        }
        else
        {
            $databack1 = round($tempDataTotal['back1']);
        }
    }
    else
    {
        $dataTotal = "0";
        $dataAmount = "0";
        $databack2 = "0";
        $databack1 = "0";
    }
    if (isset($modDiffArr[$val]))
    {
        $winlostTemp = ( $dataAmount - $databack1 ) / $modDiffArr[$val];
    }
    else
    {
        $winlostTemp = $dataAmount - $databack1;
    }
    $numbersArr = getNumArr_6H($val);
    $numberstr = implode(",", $numbersArr);
    $winlostTemp = round($winlostTemp);
    $rArr[$val_subid] = my_array_fill_keys($numbersArr, array(0 - 1, 0, 0, 0, $winlostTemp, ""));
    $rWin[$val_subid] = my_array_fill_keys($numbersArr, $winlostTemp);
    $rAmn[$val_subid] = my_array_fill_keys($numbersArr, 0);
    $rs = $BetTotal_6h->getDataListByNumSs($lotto_id, $val, "", $showid, $diskStr, $split, $ratemod);
    while (!$rs->eof)
    {
        if (isset($modDiffArr[$val]))
        {
            $winlost = ( $dataAmount - $databack1 ) / $modDiffArr[$val] - $rs->f['amount_rate'];
        }
        else
        {
            $winlost = $dataAmount - $rs->f['amount_rate'] - $databack1;
        }
        $winlost = round($winlost);
        $totalnum = intval($rs->f['totalnum']);
        $amount = $rs->f['amount'];
        $amount = round($amount);
        $rate = floatval($rs->f['rate']);
        $numbers = (string) $rs->f['numbers'];
        $rate = floatval($rs->f['rate']);
        if ($time < $rs->f['updatetime'])
        {
            $bgclass = "namount";
        }
        else
        {
            $bgclass = "";
        }
        $rArr[$val_subid][$numbers] = array($numbers, $totalnum, $amount, $rate, $winlost, $bgclass);
        $rWin[$val_subid][$numbers] = $winlost;
        $rAmn[$val_subid][$numbers] = $amount;
        $rs->movenext();
    }
    if ($dataTotal == 0)
    {
        $orderTemp = 2;
    }
    else if (isset($orderBetArr[$val]))
    {
        $orderTemp = $order;
    }
    else
    {
        $orderTemp = 2;
    }
    switch ($orderTemp)
    {
        case 0 :
            $tempArr = $rWin[$val_subid];
            asort($tempArr);
            reset($tempArr);
            break;
        case 1 :
            $tempArr = $rAmn[$val_subid];
            asort($tempArr);
            reset($tempArr);
            break;
        case 2 :
            $tempArr = my_array_fill_keys($numbersArr, 0);
            break;
    }
    $orderNumArr[$val_subid] = $tempArr;
    $showStr .= $val_subid;
    if ($ratemod == 0)
    {
        $rateArr = getRateArr($cid, $val, $lotto_id, "a");
    }
    foreach ($orderNumArr[$val_subid] as $orderNumArrkey => $orderNumArrval)
    {
        $rArrTemp = $rArr[$val_subid][$orderNumArrkey];
        $showStr .= ",{$orderNumArrkey}@" . ( $ratemod ? $rArrTemp[3] : $rateArr[$orderNumArrkey] ) . "@{$rArrTemp[1]}@{$rArrTemp[2]}@{$rArrTemp[4]}";
    }
    $showStr .= "\n";
}
header("Cache-Control: no-cache, must-revalidate");
header("Content-Type: text/plain");
echo $showStr;
exit();
?>